package com.ejuornal.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.Page;
import com.ejuornal.bean.vo.EUserPeriodical;
import com.ejuornal.dao.EditorVoDao;

@Component("editorVoDao")
public class EditorVoDaoImpl extends DaoSupport<EUserPeriodical> implements EditorVoDao {
	@Override
	public List<EUserPeriodical> findByEditorChiefId(int editorChiefId) {
		String sql = "SELECT * from v_e_user_per where periodicalId in "+
				"(select pp.periodicalId from t_periodical pp where pp.userId = ?) and status = 1";
		List<EUserPeriodical> list = super.getJdbcTemplate().query(sql, 
						new Object[]{editorChiefId}, 
						new EUserPeriodicalMapper());
		return list;
	}
	
	@Override
	public EUserPeriodical findById(int userId) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<EUserPeriodical> findByPeriodicalId(int periodicalId) {
		String sql = "select * from v_e_user_per where periodicalId =?";
		List<EUserPeriodical> list = super.getJdbcTemplate().query(sql, 
				new Object[]{periodicalId}, 
				new EUserPeriodicalMapper());
		return list;
	}

	@Override
	public void add(String sql, Object... objs) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void batchDelete(String sql, int... ids) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(String sql, Object... objs) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Page<EUserPeriodical> find(int current_record, String url) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<EUserPeriodical> find(int current_record, String url,
			String hsql, Object[] objs) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<EUserPeriodical> find(int current_record, String url,
			String sql_1, String sql_2, Object[] objs) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Page<EUserPeriodical> find(int current_record, String url,
			int pageSize, String sql_1, String sql_2, Object[] objs) {
		// TODO Auto-generated method stub
		return null;
	}
	
	final class EUserPeriodicalMapper implements RowMapper<EUserPeriodical> {
		public EUserPeriodical mapRow(ResultSet rs, int rowNum)
				throws SQLException {
			EUserPeriodical editorExt = new EUserPeriodical();
			editorExt.setCompany(rs.getString("company"));
			editorExt.setEditorId(rs.getInt("editorId"));
			editorExt.setEmail(rs.getString("email"));
			editorExt.setHostUnit(rs.getString("hostUnit"));
			editorExt.setLeaveDate(rs.getDate("leaveDate"));
			editorExt.setName(rs.getString("name"));
			editorExt.setPanName(rs.getString("panName"));
			editorExt.setPeriodicalId(rs.getInt("periodicalId"));
			editorExt.setPstatus(rs.getString("pstatus"));
			editorExt.setRealName(rs.getString("realName"));
			editorExt.setStatus(rs.getString("status"));
			editorExt.setTel(rs.getString("tel"));
			editorExt.setUserId(rs.getInt("userId"));
			editorExt.setUserName(rs.getString("userName"));
			editorExt.setWorkDate(rs.getDate("workDate"));
			return editorExt;
		}
	}

	

}
